#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 参考: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import SGDRegressor
import tools

clf = SGDRegressor(max_iter=1000)
(X, Y) = tools.oneSamples()
Y = Y.A1

clf.fit(X, Y)
hatY = clf.predict(X)

plt.plot(X[:, 1], Y, label='sample')
plt.legend()
plt.plot(X[:, 1], hatY, label='sgd')
plt.legend()
plt.savefig('sgd.png')
